<template>
  <el-dialog
    v-el-drag-dialog
    :title="!dataForm.id ? '详情' : '详情'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
    <el-form-item label="创建时间:" prop="createTime">
      <span>{{dataForm.createTime}}</span>
    </el-form-item>
    <el-form-item label="主版本号:" prop="masterVer">
      <span>{{dataForm.masterVer}}</span>
    </el-form-item>
    <el-form-item label="内部版本号:" prop="assistVer">
      <span>{{dataForm.assistVer}}</span>
    </el-form-item>
    <el-form-item label="下载地址:" prop="downUrl">
      <span>{{dataForm.downUrl}}</span>
    </el-form-item>
    <el-form-item label="更新描述:" prop="description">
      <span>{{dataForm.description}}</span>
    </el-form-item>
    <el-form-item label="更新时间:" prop="updateTime">
      <span>{{dataForm.updateTime}}</span>
    </el-form-item>
    <el-form-item label="是否强制升级:" prop="mustBe">
      <!-- <span>{{dataForm.mustBe == 1 ? '强制' : '不强制'}}</span> -->
      <span v-if="dataForm.mustBe == 1">
        <span v-if="dataForm.appType === '1' || dataForm.appType === '0'">强制</span>
      </span>
      <span v-if="dataForm.mustBe == 0">
        <span v-if="dataForm.appType === '1' || dataForm.appType === '0'">不强制</span>
      </span>
      <span v-if="dataForm.strongUpdateApp == 0">
        <span v-if="dataForm.appType === '2' || dataForm.appType === '3'">不强制</span>
      </span>
      <span v-if="dataForm.strongUpdateApp == 1">
        <span v-if="dataForm.appType === '2' || dataForm.appType === '3'">强制</span>
      </span>
    </el-form-item>
    <el-form-item label="App类型:" prop="appType">
      <span>{{dataForm.appType == 0 ? '安卓用户端' : dataForm.appType == 1 ? '安卓商家端' : dataForm.appType == 2 ? 'iOS用户端' : dataForm.appType == 3 ?'iOS商家端' : ''}}</span>
    </el-form-item>
    </el-form>
    <!-- <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span> -->
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          createTime: '',
          masterVer: '',
          assistVer: '',
          downUrl: '',
          description: '',
          updateTime: '',
          mustBe: '',
          appType: '',
          strongUpdateApp: ''
        },
        dataRule: {}
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/app/version/getVersionById/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.createTime = data.data.createTime
                this.dataForm.masterVer = data.data.masterVer
                this.dataForm.assistVer = data.data.assistVer
                this.dataForm.downUrl = data.data.downUrl
                this.dataForm.description = data.data.description
                this.dataForm.updateTime = data.data.updateTime
                this.dataForm.mustBe = data.data.mustBe
                this.dataForm.appType = data.data.appType
                this.dataForm.strongUpdateApp = data.data.strongUpdateApp
              }
            })
          }
        })
      }
      // 表单提交
      // dataFormSubmit () {
      //   this.$refs['dataForm'].validate((valid) => {
      //     if (valid) {
      //       this.$http({
      //         url: this.$http.adornUrl(`/generator/shoppingandroidapp/${!this.dataForm.id ? 'save' : 'update'}`),
      //         method: 'post',
      //         data: this.$http.adornData({
      //           'id': this.dataForm.id || undefined,
      //           'createtime': this.dataForm.createtime,
      //           'masterver': this.dataForm.masterver,
      //           'assistver': this.dataForm.assistver,
      //           'downurl': this.dataForm.downurl,
      //           'description': this.dataForm.description,
      //           'updatetime': this.dataForm.updatetime,
      //           'mustbe': this.dataForm.mustbe,
      //           'appType': this.dataForm.appType
      //         })
      //       }).then(({data}) => {
      //         if (data && data.code === 0) {
      //           this.$message({
      //             message: '操作成功',
      //             type: 'success',
      //             duration: 1500,
      //             onClose: () => {
      //               this.visible = false
      //               this.$emit('refreshDataList')
      //             }
      //           })
      //         } else {
      //           this.$message.error(data.msg)
      //         }
      //       })
      //     }
      //   })
      // }
    }
  }
</script>
